package com.ruoyi.web.controller.life;

import java.util.List;

import com.ruoyi.system.domain.life.LifeGiftList;
import com.ruoyi.system.service.life.ILifeGiftListService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人情世故Controller
 *
 * @author ruoyi
 * @date 2024-01-23
 */
@RestController
@RequestMapping("/life/list")
public class LifeGiftListController extends BaseController {
    @Autowired
    private ILifeGiftListService lifeGiftListService;

    /**
     * 查询人情世故列表
     */
    @PreAuthorize("@ss.hasPermi('life:list:list')")
    @GetMapping("/list")
    public TableDataInfo list(LifeGiftList lifeGiftList) {
        startPage();
        List<LifeGiftList> list = lifeGiftListService.selectLifeGiftListList(lifeGiftList);
        if (list.size() > 0) {
            list.get(0).setTotalMoney(lifeGiftListService.getTotalMoney(lifeGiftList));
        }
        return getDataTable(list);
    }

    /**
     * 导出人情世故列表
     */
    @PreAuthorize("@ss.hasPermi('life:list:export')")
    @Log(title = "人情世故", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LifeGiftList lifeGiftList) {
        List<LifeGiftList> list = lifeGiftListService.selectLifeGiftListList(lifeGiftList);
        ExcelUtil<LifeGiftList> util = new ExcelUtil<LifeGiftList>(LifeGiftList.class);
        util.exportExcel(response, list, "人情世故数据");
    }

    /**
     * 获取人情世故详细信息
     */
    @PreAuthorize("@ss.hasPermi('life:list:query')")
    @GetMapping(value = "/{lGiftId}")
    public AjaxResult getInfo(@PathVariable("lGiftId") Long lGiftId) {
        return success(lifeGiftListService.selectLifeGiftListByLGiftId(lGiftId));
    }

    /**
     * 新增人情世故
     */
    @PreAuthorize("@ss.hasPermi('life:list:add')")
    @Log(title = "人情世故", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LifeGiftList lifeGiftList) {
        return toAjax(lifeGiftListService.insertLifeGiftList(lifeGiftList));
    }

    /**
     * 修改人情世故
     */
    @PreAuthorize("@ss.hasPermi('life:list:edit')")
    @Log(title = "人情世故", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LifeGiftList lifeGiftList) {
        return toAjax(lifeGiftListService.updateLifeGiftList(lifeGiftList));
    }

    /**
     * 删除人情世故
     */
    @PreAuthorize("@ss.hasPermi('life:list:remove')")
    @Log(title = "人情世故", businessType = BusinessType.DELETE)
    @DeleteMapping("/{lGiftIds}")
    public AjaxResult remove(@PathVariable Long[] lGiftIds) {
        return toAjax(lifeGiftListService.deleteLifeGiftListByLGiftIds(lGiftIds));
    }
}
